import axios from "axios"
import Vue from "vue"
import qs from "qs"
var rootApi=process.env.VUE_APP_ROOTAPI;

axios.defaults.baseURL = rootApi;
axios.interceptors.request.use(function(config){
	const token = localStorage.getItem("token");
	config.headers.common["Authorization"]="Bearer "+token;
	return config;
}, function (error) {
    // Do something with request error
    return Promise.reject(error);
  });
 
//响应的拦截器
axios.interceptors.response.use(function (response) {
    // Do something with response data
    return response;
  }, function (error) {
    // Do something with response error
    return Promise.reject(error);
  });


var myaxios={
	get:(url,prams)=>{
		
		return axios.get(url,{prams:prams})
		.then((response)=>{
			return response;
		})
	},
	post:(url,data,config)=>{
		return axios.post(url,qs.stringify(data),config).
		then((response)=>{
			return response;
		})
	}
}
Vue.prototype.$http = myaxios;
export default myaxios;
